const util = require('../../utils/util.js');
const api = require('../../config/api.js');
Page({
    data: {
      list:[],
        page: 1,
        totalPages: 1,
    },

    onShareAppMessage() {
        return {};
    },
    onLoad(){

    },
    onShow() {
        this.setData({
            list: [],
            totalPages: 1
        });
        this.getIndexData();
    },
    view_180nClick(e) {
        const id = e.currentTarget.dataset.id;
        wx.navigateTo({url: '/pages/ReceiptAdd/ReceiptAdd?id=' + id});
    },
    view_4OnClick() {
        wx.navigateTo({url: '/pages/ReceiptAdd/ReceiptAdd?'});
    },
    getIndexData() {
        let that = this;
        util.request(api.ReceiptList, {
            pageRequestVo: {
                pageNum: this.data.page,
                pageSize: 10
            }
        }, 'POST').then(function (res) {
            if (res.errno === 200) {
                that.setData({
                    list: that.data.list.concat(res.data.list||[]),
                    totalPages: res.data.pages
                });

            }
        });
    },
    onPullDownRefresh() {
        wx.stopPullDownRefresh() //停止下拉刷新
    },
    onReachBottom() {
        if (this.data.page < this.data.totalPages) {
            this.setData({
                page: this.data.page + 1
            });
            this.getIndexData();
        } else {
            wx.showToast({
                title: '没有更多了',
                icon: 'none',
                duration: 2000
            });
            return false;
        }
    },
});
